﻿package com.scn.base.tags;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.log4j.Logger;

public final class ContextPathTag extends TagSupport { 
	private static Logger  log = Logger.getLogger(ContextPathTag.class);
	
	/**
	 * tlist:header 标签开始
	 *
	 * @exception JspException
	 */
	public int doStartTag() throws JspException {
	  return SKIP_BODY;
	}

	/**
	 * 从session中读取错误列表
	 *
	 * @exception JspException
	 */
	public int doEndTag() throws JspException
	{
	  JspWriter writer = pageContext.getOut();
	  try
	  { 
		String sRootPath = ((HttpServletRequest)pageContext.getRequest()).getContextPath();
		if(sRootPath.endsWith("/"))sRootPath=sRootPath.substring(sRootPath.length()-1);
		 
		writer.print(sRootPath);
	  }
	  catch (IOException ioe)
	  {
		log.error(ioe.getMessage());
	  }
	  return EVAL_PAGE;
	}

}